<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<%
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath() + "/";
    request.setAttribute("basePath", basePath);
%>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>后台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="${basePath}css/font.css">
    <link rel="stylesheet" href="${basePath}css/xadmin.css">
    <script type="text/javascript" src="${basePath}js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="${basePath}lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${basePath}js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" href="${basePath}css/xcConfirm.css" type="text/css">
    <script src="${basePath}js/xcConfirm.js"></script>
    <script src="${basePath}lib/My97DatePicker/WdatePicker.js"></script>
    <link href="<%=basePath %>/lib/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css"/>
</head>
<script>
    $(function () {
        try {
            var index = parent.layer.getFrameIndex(window.name);
            window.parent.location.reload();
            parent.layer.close(index);
        } catch (e) {

        }
    });
</script>
<body>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so layui-form-pane" method="get">
            <input class="layui-input" placeholder="章节名称" name="chapterName" value="${page.conMap.chapterName}">
            <input class="layui-input" placeholder="评论人" name="userName" value="${page.conMap.userName}">
            <div class="layui-input-inline">
                <select name="commentType">
                    <option value="">评论类型</option>
                    <option value="1" ${page.conMap.commentType==1 ? 'selected="selected"':''}>点赞</option>
                    <option value="2" ${page.conMap.commentType==2 ? 'selected="selected"':''}>评论</option>
                </select>
            </div>
            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
        <button class="layui-btn" lay-filter="sreach"
                onclick="x_admin_show('增加','${basePath}courseComment/pageLoad/0')">
            <i class="layui-icon"></i>增加
        </button>
        <button class="layui-btn" onclick="delTr2()"><i class="layui-icon">&#xe615;</i>删除</button>
        <span class="x-right" style="line-height:40px">共有数据：${page.totalCount} 条</span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <td><input id="allCkb" type="checkbox"/></td>
            <td>序号</td>
            <td>章节名称</td>
            <td>评论类型</td>
            <td>评论人</td>
            <td>评论时间</td>
            <td>评论内容</td>
            <td>是否回复</td>
            <td>是否推荐</td>
            <td>是否置顶</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        <c:if test="${not empty page.results}">
            <c:forEach items="${page.results}" var="result" varStatus="vs">
                <tr>
                    <td><input type='checkbox' name='ckb' value="${result.id }"/></td>
                    <td>${(page.actulPageNo - 1) * 15 + vs.count}</td>
                    <td>${result.chapterName}</td>
                    <td>
                        <c:if test="${result.commentType eq '1'}">点赞</c:if>
                        <c:if test="${result.commentType eq '2'}">评论</c:if>
                    </td>
                    <td>${result.userName}</td>
                    <td>${result.commentTime}</td>

                    <td>
                        <c:if test="${fn:length(result.commentContent)>'20'}">
                            <span style="cursor:pointer"
                                  onclick="showMsg('${result.commentContent}')">${fn:substring(result.commentContent,0,20)}...</span>
                        </c:if>
                        <c:if test="${fn:length(result.commentContent)<='20'}">
                            <span style="cursor:pointer"
                                  onclick="showMsg('${result.commentContent}')">${result.commentContent}</span>
                        </c:if>
                    </td>

                    <td>
                        <c:if test="${empty result.reply}">否</c:if>
                        <c:if test="${not empty result.reply}">是</c:if>
                    </td>
                    <td>
                        <c:if test="${result.rec_flag eq '1'}">是</c:if>
                        <c:if test="${result.rec_flag eq '2'}">否</c:if>
                    </td>
                    <td id="tr${result.id }">
                        <c:if test="${result.isTop eq '1'}">是</c:if>
                        <c:if test="${result.isTop eq '2'}">否</c:if>
                    </td>
                    <td>
                        <button class="layui-btn layui-btn layui-btn-xs"
                                onclick="x_admin_show('编辑','${basePath}courseComment/pageLoad/${result.id}')">
                            <i class="layui-icon">&#xe642;</i>编辑
                        </button>
                        <button class="layui-btn layui-btn layui-btn-xs"
                                onclick="x_admin_show('回复','${basePath}courseComment/DownLoadReply/${result.id}')">
                            <i class="layui-icon">&#xe642;</i>回复
                        </button>
                        <button class="layui-btn-danger layui-btn layui-btn-xs" onclick="_del('${result.id}')"
                                href="javascript:;"><i class="layui-icon">&#xe640;</i>删除
                        </button>
                        <button class="layui-btn layui-btn-warm layui-btn-xs"
                                onclick="designated('${result.id}')"><i class="layui-icon">&#xe642;</i>置顶
                        </button>
                    </td>
                </tr>
            </c:forEach>
        </c:if>
        </tbody>
    </table>
    <div class="page">
        <c:if test="${page.totalPageNo > 1 }">
            <div>
                <a class="num" href='${basePath}${page.url}?pageNo=1${page.params}'>首页</a>
                <c:if test="${page.actulPageNo > 1 }">
                    <a class="prev"
                       href='${basePath}${page.url}?pageNo=${page.actulPageNo - 1}${page.params}'>上一页</a>
                </c:if>
                <c:forEach var="pno" items="${page.showNums }">
                    <c:choose>
                        <c:when test="${pno == page.actulPageNo}">
                            <span class="current"> ${pno }</span>
                        </c:when>
                        <c:otherwise>
                            <c:if test="${not empty pno}">
                                <a class="num"
                                   href='${basePath}${page.url}?pageNo=${pno  }${page.params}'>${pno }</a>
                            </c:if>
                        </c:otherwise>
                    </c:choose>
                </c:forEach>
                <c:if test="${page.actulPageNo  < page.totalPageNo }">
                    <a class="next" href='${basePath}${page.url}?pageNo=${page.actulPageNo + 1}${page.params}'>下一页</a>
                </c:if>
                <a class="num" href='${basePath}${page.url}?pageNo=${page.totalPageNo }${page.params}'>尾页</a>
            </div>
        </c:if>
    </div>
</div>
<script>
    layui.use(['form'], function () {
        form = layui.form;

    });

    function _del(id) {
        layer.confirm('确认要删除吗？', function () {
            var url = "${basePath}courseComment/remove/" + id;
            location.href = url;
        });
    }

    function designated(id) {
        $.ajax({
            url: '${basePath}courseComment/setTop',
            typpe: 'get',
            data: {"id": id},
            success: function (msg) {
                if (msg == "1") {
                    $("#tr" + id).text("是");
                    window.wxc.xcConfirm("置顶成功！");
                }
            }

        });
    }

    function showMsg(e) {
        window.wxc.xcConfirm(e);
    };

    function delTr2() {
        if (confirm("确认删除吗？删除之后，不可恢复") == true) {
            var ids = [];
            $("input[name=ckb]:checked").each(function () {
                ids.push($(this).val());
            });
            $.ajax({
                type: "POST",
                async: true,
                data: {"ids": ids},
                dataType: 'json',
                url: "<%=basePath %>courseComment/batchdeleteComment",
                success: function (data) {
                    $("input[name=ckb]:checked").each(function () {
                        $(this).parent().parent().remove();
                    });
                    alert("操作成功！");
                },

            });
        }

    }
</script>
</body>

</html>